package com.ithinks.flow.common.utils.protocol.netty.udp.broadcast.acceptside;

import com.ithinks.flow.common.utils.protocol.udp.broadcast.LogMsg;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Description
 * @ClassName LongEventHandler
 * @Author MR.LI
 * @date 2020.12.13 17:11
 */
public class LongEventHandler extends SimpleChannelInboundHandler<LogMsg> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, LogMsg logMsg) throws Exception {
        StringBuilder builder = new StringBuilder();
        builder.append(logMsg.getTime());
        builder.append("[");
        builder.append(logMsg.getSource());
        builder.append("] : [");
        builder.append(logMsg.getMsgId());
        builder.append("] :");
        builder.append(logMsg.getMsg());
        System.out.println(builder.toString());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
